001    /**
002     * Java Gui Builder - A library to build GUIs using an XML file.
003     * Copyright 2002, 2003 (C) François Beausoleil
004     *
005     * This library is free software; you can redistribute it and/or
006     * modify it under the terms of the GNU Lesser General Public
007     * License as published by the Free Software Foundation; either
008     * version 2.1 of the License, or (at your option) any later version.
009     *
010     * This library is distributed in the hope that it will be useful,
011     * but WITHOUT ANY WARRANTY; without even the implied warranty of
012     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013     * Lesser General Public License for more details.
014     *
015     * You should have received a copy of the GNU Lesser General Public
016     * License along with this library; if not, write to the Free Software
017     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018     */
019    
020    package jgb.builder.utils;
021    
022    import java.util.ArrayList;
023    import java.util.List;
024    
025    /**
026     * @since 0.2a
027     * @author Francois Beausoleil, <a href="mailto:fbos@users.sourceforge.net">fbos@users.sourceforge.net</a>
028     */
029    public class ParametersAccumulator {
030        private List types = new ArrayList();
031        private List values = new ArrayList();
032    
033        public void addParameter(Class type, Object value) {
034            types.add(type);
035            values.add(value);
036        }
037    
038        public Class[] createParametersArray() {
039            Class[] typesArray = new Class[types.size()];
040            for (int i = 0; i < typesArray.length; i++) {
041                typesArray[i] = (Class)types.get(i);
042            }
043    
044            return typesArray;
045        }
046    
047        public Object[] createValuesArray() {
048            Object[] valuesArray = new Object[types.size()];
049            for (int i = 0; i < valuesArray.length; i++) {
050                valuesArray[i] = values.get(i);
051            }
052    
053            return valuesArray;
054        }
055    
056        public int getParamCount() {
057            return types.size();
058        }
059    
060        public List getParameterValues() {
061            return new ArrayList(values);
062        }
063    
064        public List getParameterTypes() {
065            return new ArrayList(types);
066        }
067    
068        public String toString() {
069            StringBuffer buf = new StringBuffer();
070            for (int i = 0; i < types.size(); i++) {
071                buf.append(types.get(i)).append(" ").append(values.get(i));
072                if (i < types.size() - 1) {
073                    buf.append(", ");
074                }
075            }
076    
077            return buf.toString();
078        }
079    }